<?php namespace Admin\Controller; 

use Admin\Model\Cat;

/**
 * 商品栏目管理
 * 
 */
class CatController extends AuthController{

	protected $db;
	//构造函数
	public function __init()
	{
		$this->db = new Cat;
	}
	
    //显示商品栏目目录
    public function index(){
    	
		$data = $this->db->getAll();
		
       	View::with('data',$data)->make();
		
    }
	
	//添加栏目
	public function add()
	{
		if(IS_POST){
			if($this->db->store()){
				View::success('添加栏目成功',U('index'));
			}else{
				View::error($this->db->getError());
			}
		}else{
			$cat = $this->db->getAll();
			View::with('cat',$cat)->make();
		}
		
	}
	
	//修改栏目
	public function edit()
	{
		if(IS_POST){
			if($this->db->edit()){
				View::success('修改栏目成功',U('index'));
			}else{
				View::error($this->db->getError());
			}
		}else{
			$file = $this->db->one($_GET['cat_id']);
//			p($file);die;
			$cat = $this->db->getAll();
			View::with('file',$file)->with('cat',$cat)->make();
		}
		
	}
	
	
}
